package com.mrx.xcitools.advice;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Mr.X
 * @since 2024-03-11 15:47
 **/
@RestControllerAdvice
public class GlobalExceptionAdvice {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionAdvice.class);

    @ExceptionHandler(Throwable.class)
    public ResponseEntity<?> exceptionHandler(Throwable throwable) {
        logger.warn("出现异常", throwable);
        return ResponseEntity.internalServerError()
                .body(throwable.getMessage());
    }

}
